﻿SELECT
	[main].object_id AS [ObjectId],
	[main].[name] AS [ObjectName],
	[mod].[uses_ansi_nulls] AS [UsesAnsiNulls],
	[schema].[name] AS [SchemaName],
	[cols].[name] AS [ColumnName],
	[cols].[column_id] AS [ColumnId],
	
	-- sysModule Information
	[mod].[definition] AS [Definition],
	[mod].[uses_ansi_nulls] AS [UsesAnsiNulls],
	[mod].[uses_quoted_identifier] AS [UsesQuotedIdentifier],
	[mod].[is_schema_bound] AS [IsSchemaBound],
	[mod].[uses_database_collation] AS [UsesDatabaseCollation],

	-- Type information
	[systypes].[name] AS [TypeName],
	[cols].[max_length] AS [MaxLength],
	[cols].[precision] AS [Precision],
	[cols].[scale] AS [Scale],
	[cols].[is_nullable] AS [IsNullable],

	[cols].[collation_name] AS [Collation],
	[cols].[is_ansi_padded] AS [IsAnsiPadded],
	[cols].[is_rowguidcol] AS [IsRowGuid],
	
	-- Full text data
	CASE [ftcols].object_id WHEN [main].object_id THEN 1 ELSE 0 END AS [IsFullTextIndexed]

FROM sys.views [main]
INNER JOIN sys.schemas [schema] ON [main].[schema_id] = [schema].[schema_id]
INNER JOIN sys.sql_modules [mod] ON [main].object_id = [mod].object_id

-- Get normal columns
LEFT OUTER JOIN sys.columns [cols] ON [main].object_id = [cols].object_id
LEFT OUTER JOIN sys.systypes [systypes] ON [cols].[system_type_id] = [systypes].[xtype]

-- Get Full text columns
LEFT OUTER JOIN sys.fulltext_index_columns [ftcols] ON [main].object_id = [ftcols].object_id AND [cols].[column_id] = [ftcols].[column_id]

WHERE
	[systypes].[name] != 'sysname'
-- [WHERECLAUSE]

ORDER BY
	[main].[name],
	[cols].[column_id]
